var ns, toast, UIActionProgress, UISearchBar;
var app = new Vue({
    el: '#app',
    data: {
        IsMain:1,
        list: [],
        TypeID:0,
        IsShow:false,
        form: {
            pageindex: 0,
            pagesize: 2,
        },
        showsearch:false,
        showTop:false,
        name:'',
        typeurl:'',
        moduleList:[],
        touchID:0,
        SortOrder:0,

    },
    methods: {
        get_data: function () {
            var that = this;
            var options = {};
            ns.post(options, function (succeed, data, err) {
                console.log(JSON.stringify(data));
                if (succeed) {
                    that.list=data;
                    for (let i = 0; i < that.list.length; i++) {
                        that.list[i].time=moment(that.list[i].time).format('MM-DD HH:mm');
                    }
                } 
            },{
                command: 'App/System/GetNotifyList'
            });
        },


        //点击遮罩关闭弹窗
        doHideSearch:function(){
            var that=this;
            that.showsearch = false;
            that.showTop=false;
            that.IsMain=1;
            that.get_data();
        },


        //删除
        deletelist:function(){
            var that=this;
            var isshow=!that.IsShow;
            that.moduleList=[];
            that.moduleList.push({
                ID:that.touchID,
                SortOrder:that.SortOrder,
                IsShow:isshow,
            });
            var options = {};
            options.action = "savemodulesuctom";
            options.moduleList = JSON.stringify(that.moduleList);
            options.IsSortOrder=0;
            ns.post(options, function(succeed, data, err) {
                that.showTop=false;
                if (data.status==true) {
                    api.toast({
                        msg:'删除成功',
                        duration: 2000,
                        location: 'bottom'
                    });
                    that.get_data();
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }, {
                toast: true
            });
        },
        do_opentypelist:function(ID){
            ns.openWin('tongzhixiaoxidetail_frm', '消息详情', {
                id:ID
            });
        },
    }
});
apiready = function () {
    api.parseTapmode();
    ns = window.Foresight.Util;
    UIActionProgress = api.require('UIActionProgress');
    toast = new auiToast();
    app.get_data();

    ns.init_pull(true);
    api.addEventListener({
        name: 'isreadtrue'
    }, function (ret, err) {
        if (ret) {
            setTimeout(function () {
                app.get_data();
            }, 500);
        } else {
            api.toast({
                msg: err,
                duration: 2000,
                location: 'bottom'
            });
        }
    });
    api.addEventListener({
        name: 'isreadCustomer'
    }, function () {
        app.get_data();
    });
    api.addEventListener({
        name: 'isreadEquipment'
    }, function () {
        app.get_data();
    });
    api.addEventListener({
        name: 'isreadTongzhi'
    }, function () {
        app.get_data();
    });

    api.addEventListener({
        name: 'home_new_updata'
    }, function () {
        app.get_data();
    });

}
